package org.example.myleet.a001;

import java.util.ArrayList;
import java.util.List;

public class Solution {

    private static final double LIMIT = 166;

    private List<String> result;

    public void solve(Main.House[] houses) {
        result = new ArrayList<>();
        dfs(houses, new ArrayList<>(), 0);
        for (String s : result) {
            System.out.println(s);
        }
    }

    private void dfs(Main.House[] houses, List<Main.House> selected, double sum) {
        if (sum > LIMIT) {
            return;
        }
        if (LIMIT - sum < 2) {
            StringBuilder sb = new StringBuilder();
            for (Main.House house : selected) {
                sb.append('{').append(house.getName()).append(':').append(house.getArea()).append('}').append('-');
            }
            sb.append(String.format("%.4f", sum)).append('-').append(String.format("%.4f", LIMIT - sum));
            result.add(sb.toString());
        }
        for (Main.House house : houses) {
            selected.add(house);
            sum += house.area;
            dfs(houses, selected, sum);
            sum -= house.area;
            selected.remove(selected.size() - 1);
        }
    }
}
